<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>学生基础数据采集</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" href="/layui/css/layui.css"/>
</head>


<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/layui/layui.all.js"></script>
<script type="text/javascript" src="/js/jquery-2.0.3.min.js"></script>
<body>
<div th:if="${message}">
    <h2 th:text="${message}"/>
</div>
<div id="box">
    <input type="text" name="search" placeholder="请输入身份证" id="idCard">
    <button id="search" type="button" class="layui-btn layui-btn-normal">搜索</button>

</div>
<div>
    <form method="post" enctype="multipart/form-data" action="/upLoadStudentBasicInfo">
        <table>
            <tr>
                <td>上传文件：</td>
                <td><input type="file" name="file" /></td>
            </tr>

            <tr>
                <td></td>
                <td><input type="submit" value="上传" /></td>
            </tr>
        </table>
    </form>


</div>
<button type="button" onclick="downExcel()">基础数据表模板下载</button>
<div>
    <ul>
        <li th:each="file : ${files}">
            <a th:href="${file}" th:text="${file}" />
        </li>
    </ul>
</div>
<table id="test3" lay-filter="test3" class="layui-hide"></table>
<script>
    var tableData = new Array();
        $("#search").click(function () {
            debugger;
            var idCard=$("#idCard").val();
            $.ajax({
                url: "findByIdCard",
                type: "get",
                data: {"idCard":idCard},
                dataType: "json",
                success: function (result) {
                    tableData=result
                    layui.use('table', function () {
                        debugger;
                        var table = layui.table;
                        table.render({
                            elem: '#test3'
                            , data: tableData.data
                            , cols: [
                                [
                                    {title: '序号', type: 'numbers', Width: 20}
                                    , {field: 'studentName', title: '学生姓名', edit: 'text', minWidth: 80}
                                    , {field: 'idCard', title: '身份证', edit: 'text', minWidth: 180, sort: true}
                                    , {field: 'studentBirthday', title: '出生年月', minWidth: 80, edit: 'text'}
                                    , {field: 'entrance', title: '入学口', minWidth: 100, edit: 'text'}
                                    , {field: 'studentXJ', title: '学籍状态', minWidth: 80, edit: 'text'}
                                    , {field: 'studentRegistrationNo', title: '学籍注册号', minWidth: 80, edit: 'text'}
                                ]
                            ]
                            , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                                , curr: 1 //设定初始在第 1 页
                                , groups: 1 //只显示 1 个连续页码
                                , first: false //不显示首页
                                , last: false //不显示尾页
                            }
                            , done: function (res, curr, count) {
                                debugger;
                                for (var i = 0; i < res.data.length; i++)   //遍历返回数据
                                {
                                    if (res.data[i].achievement > 100 || res.data[i].achievement < 0)    //设置条件
                                    {
                                        $("table tbody tr").eq(i + 2).find('td').eq(7).css('color', 'red')    //改变满足条件行的颜色
                                    }
                                }
                            }

                        });
                        table.on('edit(test3)', function (obj) {
                            debugger;
                            var value = obj.value //得到修改后的值
                                , data = obj.data //得到所在行所有键值
                                , field = obj.field; //得到字段
                            layui.use('jquery', function () {
                                var $ = layui.$;
                                $.ajax({
                                    type: 'get',
                                    url: "updateStudentBasicData", // ajax请求路径
                                    data: {
                                        id: data.id,
                                        field: field,
                                        value: value
                                    },
                                    success: function (data) {
                                        $("#test3").empty();
                                        table.reload("test3", { //此处是上文提到的 初始化标识id
                                            page: {
                                                curr: 1
                                            }
                                        });
                                        layer.msg('修改成功');
                                    }
                                });
                            });
                        })
                    })
                }
            })
        })

            $.ajax({
                url: "findAllStudentBasicData",
                type: "get",
                dataType: "json",
                success: function (result) {
                    debugger;
                    tableData = result;
                    layui.use('table', function () {
                        debugger;
                        var table = layui.table;
                        table.render({
                            elem: '#test3'
                            , data: tableData.data
                            , cols: [
                                [
                                    {title: '序号', type: 'numbers', Width: 20}
                                    , {field: 'studentName', title: '学生姓名', edit: 'text', minWidth: 80}
                                    , {field: 'idCard', title: '身份证', edit: 'text', minWidth: 180, sort: true}
                                    , {field: 'studentBirthday', title: '出生年月', minWidth: 80, edit: 'text'}
                                    , {field: 'entrance', title: '入学口', minWidth: 100, edit: 'text'}
                                    , {field: 'studentXJ', title: '学籍状态', minWidth: 80, edit: 'text'}
                                    , {field: 'studentRegistrationNo', title: '学籍注册号', minWidth: 80, edit: 'text'}
                                ]
                            ]
                            , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                                , curr: 1 //设定初始在第 1 页
                                , groups: 1 //只显示 1 个连续页码
                                , first: false //不显示首页
                                , last: false //不显示尾页
                            }
                            , done: function (res, curr, count) {
                                debugger;
                                for (var i = 0; i < res.data.length; i++)   //遍历返回数据
                                {
                                    if (res.data[i].achievement > 100 || res.data[i].achievement < 0)    //设置条件
                                    {
                                        $("table tbody tr").eq(i + 2).find('td').eq(7).css('color', 'red')    //改变满足条件行的颜色
                                    }
                                }
                            }

                        });
                        table.on('edit(test3)', function (obj) {
                            debugger;
                            var value = obj.value //得到修改后的值
                                , data = obj.data //得到所在行所有键值
                                , field = obj.field; //得到字段
                            layui.use('jquery', function () {
                                var $ = layui.$;
                                $.ajax({
                                    type: 'get',
                                    url: "updateStudentBasicData", // ajax请求路径
                                    data: {
                                        id: data.id,
                                        field: field,
                                        value: value
                                    },
                                    success: function (data) {
                                        $("#test3").empty();
                                        table.reload("test3", { //此处是上文提到的 初始化标识id
                                            page:{
                                                curr: 1
                                            }
                                        });
                                        layer.msg('修改成功');
                                    }
                                });
                            });
                        })

                        //点击加号按钮时，新添一行
                        /* $("#addTable").click(function () {
                        var oldData = table.cache["baseInfo"];
                        var data1 = {
                            "colName": "ID2",
                            "colNo": 0,
                            "collator": "",
                            "comments": "",
                            "dbId": 1,
                            "defVal": "",
                            "deleted": "",
                            "dispersion": 0,
                            "domainId": 0,
                            "histogram": "",
                            "isHide": "",
                            "isSerial": "F",
                            "isVirtual": "",
                            "maxVal": "",
                            "minVal": "",
                            "notNull": "T",
                            "repetRate": 0,
                            "scale": -1,
                            "serialId": 0,
                            "tableId": 1048586,
                            "timestampT": " ",
                            "typeName": "INTEGER",
                            "varying": "F",
                            "vcolNo": 0,
                            "vertNo": 0
                        };
                        oldData.push(data1);
                        table.reload('baseInfo', {
                            data: oldData
                        });
                    });
                    })*/

                    })
                }
            })


    /*$("#insert").click(function(){
        var table = layui.table;
        var s=table.cache.test3.length;
        var tr=" <tr data-index=\""+s+"\">"+
            "  <td data-field=\"id\"  data-edit='text' data-key=\"1-0-1\"><div class='layui-table-cell laytable-cell-1-0-1  '> </div></td>"+
            "  <td data-field=\"studentName\"  data-edit='text' data-key=\"1-0-2\"><div class='layui-table-cell laytable-cell-1-0-2  '> </div></td>"+
            "  <td data-field=\"studentNumber\"  data-edit='text' data-key=\"1-0-3\"><div class='layui-table-cell laytable-cell-1-0-3  '> </div></td>"+
            "  <td data-field=\"department\"  data-edit='text' data-key=\"1-0-4\"><div class='layui-table-cell laytable-cell-1-0-4  '> </div></td>"+
            "  <td data-field=\"major\"  data-edit='text' data-key=\"1-0-5\"><div class='layui-table-cell laytable-cell-1-0-5  '> </div></td>"+
            "  <td data-field=\"grade\" data-edit='text' data-key=\"1-0-6\"><div class='layui-table-cell laytable-cell-1-0-6  '> </div></td>"+
            "  <td data-field=\"achievement\"  data-edit='text' data-key=\"1-0-7\"><div class='layui-table-cell laytable-cell-1-0-7  '> </div></td>"+
            "  </tr>";
        $(".layui-table-body .layui-table  tbody").append(tr);	});
    $("#update").click(function(){
        layui.use('table', function(){
            debugger;
            var table = layui.table;
            var data=table.cache.test3;
        })
    })
    layui.use('table', function(){
        var table = layui.table;

        //监听单元格编辑
        table.on('edit(test3)', function(obj){
            debugger;
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
        });
    });*/
</script>
<script>
    function downExcel() {
        // window.open("http://127.0.0.1:8093/studentBasicFiles");
        window.open("http://192.168.7.22:8093/studentBasicFiles");
    }
</script>
</body>
</html>